﻿using TSharp.Core.Util;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;
using TSharp.Core.TestUtil;
using System.Collections.Specialized;

namespace Wicresot.CoreTests
{


    /// <summary>
    ///这是 ParameterizedUriTest 的测试类，旨在
    ///包含所有 ParameterizedUriTest 单元测试
    ///</summary>
    [TestClass()]
    public class ParameterizedUriTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            TestHelper.SetupTest();
        }
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///ParameterizedUri 构造函数 的测试
        ///</summary>
        [TestMethod()]
        public void ParameterizedUriConstructorTest()
        {
            string uriString =
                "s?bs=ce+ads+d&f=8&rsv_bp=1&rsv_spt=3&wd=%D6%D0%B9%FA+%B2%E2%CA%D4&inputT=4859";
          
            ParameterizedUri target = new ParameterizedUri(uriString,Encoding.GetEncoding("gb2312"));
            Display(target.Queries);
       
            Console.WriteLine(target);
            var a = target.ConvertWith(Encoding.UTF8);
            Console.WriteLine(a);
            var b = a.ConvertWith(Encoding.GetEncoding("gb2312"));
            Console.WriteLine(b);

            uriString =
           "om.hk/search?hl=zh-CN&source=hp&biw=&bih=&q=%E4%B8%AD%E5%9B%BD+%E6%B5%8B%E8%AF%95";
            target = new ParameterizedUri(uriString);
            Display(target.Queries);
            Console.WriteLine(target);
        }

        public void Display(NameValueCollection _queries)
        {
            StringBuilder query = new StringBuilder();
            for (int i = 0; i < _queries.Keys.Count; i++)
            {
                string[] values = _queries.GetValues(i);
                for (int j = 0; j < values.Length; j++)
                {
                    if (values[j] == null)
                        continue;
                    query.AppendFormat("{0},{1}={2}", i, _queries.Keys[i], values[j]).AppendLine();
                }
                query.AppendLine("---------------------");
            }
            Console.WriteLine(query);
        }
        /// <summary>
        ///ParameterizedUri 构造函数 的测试
        ///</summary>
        [TestMethod()]
        public void ParameterizedUriConstructorTest1()
        {
            string uriString = string.Empty; // TODO: 初始化为适当的值
            Encoding encoding = null; // TODO: 初始化为适当的值
            ParameterizedUri target = new ParameterizedUri(uriString, encoding);
            Assert.Inconclusive("TODO: 实现用来验证目标的代码");
        }

        /// <summary>
        ///SetQuery 的测试
        ///</summary>
        [TestMethod()]
        public void SetQueryTest()
        {
            string uriString = string.Empty; // TODO: 初始化为适当的值
            ParameterizedUri target = new ParameterizedUri(uriString); // TODO: 初始化为适当的值
            string queryName = string.Empty; // TODO: 初始化为适当的值
            int value = 0; // TODO: 初始化为适当的值
            ParameterizedUri expected = null; // TODO: 初始化为适当的值
            ParameterizedUri actual;
            actual = target.SetQuery(queryName, value);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }

        /// <summary>
        ///SetQuery 的测试
        ///</summary>
        [TestMethod()]
        public void SetQueryTest1()
        {
            string uriString = string.Empty; // TODO: 初始化为适当的值
            ParameterizedUri target = new ParameterizedUri(uriString); // TODO: 初始化为适当的值
            string queryName = string.Empty; // TODO: 初始化为适当的值
            Guid value = new Guid(); // TODO: 初始化为适当的值
            ParameterizedUri expected = null; // TODO: 初始化为适当的值
            ParameterizedUri actual;
            actual = target.SetQuery(queryName, value);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }

        /// <summary>
        ///SetQuery 的测试
        ///</summary>
        [TestMethod()]
        public void SetQueryTest2()
        {
            string uriString = string.Empty; // TODO: 初始化为适当的值
            ParameterizedUri target = new ParameterizedUri(uriString); // TODO: 初始化为适当的值
            string queryName = string.Empty; // TODO: 初始化为适当的值
            string value = string.Empty; // TODO: 初始化为适当的值
            ParameterizedUri expected = null; // TODO: 初始化为适当的值
            ParameterizedUri actual;
            actual = target.SetQuery(queryName, value);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }

        /// <summary>
        ///SetQuery 的测试
        ///</summary>
        [TestMethod()]
        public void SetQueryTest3()
        {
            string uriString = string.Empty; // TODO: 初始化为适当的值
            ParameterizedUri target = new ParameterizedUri(uriString); // TODO: 初始化为适当的值
            string queryName = string.Empty; // TODO: 初始化为适当的值
            Decimal value = new Decimal(); // TODO: 初始化为适当的值
            ParameterizedUri expected = null; // TODO: 初始化为适当的值
            ParameterizedUri actual;
            actual = target.SetQuery(queryName, value);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }

        /// <summary>
        ///Uri 的测试
        ///</summary>
        [TestMethod()]
        public void UriTest()
        {
            string uriString = string.Empty; // TODO: 初始化为适当的值
            ParameterizedUri target = new ParameterizedUri(uriString); // TODO: 初始化为适当的值
            Uri actual;
            actual = target.AsUri;
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
    }
}
